//
//  GroupDetailViewController.m
//  TrueLove
//
//  Created by 刘康 on 15/1/30.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "GroupDetailViewController.h"
#import "AFNetworking.h"
#import "GroupDetail.h"
#import "MyCell.h"

@interface GroupDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain)NSMutableArray *array;
@property (nonatomic, retain)UITableView *tableView;

@end

@implementation GroupDetailViewController

- (void)dealloc
{
    [_userDetail release];
    [_array release];
    [_tableView release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = self.userDetail.title;
    [self netWorkingRequestForGroupDetail];
    
    
    

    
    
}

- (void)netWorkingRequestForGroupDetail
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    NSString *str = [NSString stringWithFormat:@"http://www.hunliji.com/v1/api/app/community/posts?thread_id=%@&no=0&count=20&order=asc",[self.userDetail.myId stringValue]];
    NSLog(@"%@",str);
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
        NSArray *arr = [NSArray arrayWithArray:[dic objectForKey:@"posts"]];
        self.array = [NSMutableArray array];
        for (NSDictionary *dic in arr) {
            GroupDetail *groupDetail = [[GroupDetail alloc] init];
            [groupDetail setValuesForKeysWithDictionary:dic];
            [self.array addObject:groupDetail];
            [groupDetail release];
            [_tableView reloadData];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@",error);
    }];
}

- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
    
    

    
    [self.view addSubview:_tableView];
    [_tableView release];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 100;
    } else {
        return 80;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *str = @"reues";
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (cell == nil) {
            cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str] autorelease];
    }
    
    
    
    //取消选中的状态效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
